package com.example.controller.admin;

import com.example.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@Tag(name = "店铺接口")
@RequestMapping("/admin/shop")
public class ShopController {

    public static final String KEY="SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 更改店铺状态 1为营业中 0为打烊中
     */
    @PutMapping("/{status}")
    @Operation(summary = "更改店铺状态")
    public Result putShop(@PathVariable  Integer status){
        log.info("设置店铺状态:{}",status==1?"营业中":"打烊中");
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }


    /**
     * 商家端显示营业状态 查询操作
     */
    @GetMapping ("/status")
    @Operation(summary = "商家端显示营业状态")
    public Result getShop(){
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("获取店铺状态:{}",shopStatus==1?"营业中":"打烊中");
        return Result.success(shopStatus);
    }
}
